import {createRouter,createWebHashHistory,createWebHistory,createMemoryHistory} from "vue-router"


//1.声明routers配置，一个routes是一个数组，routes对象里面的基本属性由path和componentU组成

let routes = [
    
    {
        path:"/",
        component:()=>import("../pages/home/index.vue"),
        name:'/',
        meta:{
            //meta中的属性可以随便添加
            name:'导航首页',
        },
        children:[
            {
                path:"discover",
                component:()=>import("../pages/discover/index.vue"),
                redirect: "/discover/playlist",
                name:"discover",
                meta:{
                    name:'发现首页'
                },
                children:[
                    {
                        path:"playlist",
                        component:()=>import("../pages/discover/playlist/index.vue"),
                        name:"playlist",
                        meta:{
                            name:"歌单"
                        }
                    }
                ]
            },
            {
                path:"mine",
                component:()=>import("../pages/mine/index.vue"),
                //具名
                name:"mine",
                meta:{
                    name:"个人中心"
                }
            },
            {
                props:true,      //路由解耦合
                path:"friend/:id",
                name:"friend",
                meta:{
                    name:"朋友"
                },
                //路由独享钩子，当前路由的前置守卫
                //用法和router.beforeEach是一模一样
                beforeEnter(to,from){
                    console.log('beforeEnter--to',to)
                    console.log('beforeEnter--from',from)
                },
                component:()=>import("../pages/friend/index.vue")
            },
        ]
    },
    {
        path:"/login",
        component:()=>import("../pages/login/index.vue"),
        name:"login",
        meta:{
            name:"登入页"
        }


    },
    
]

//2.创建路由
const router = createRouter({
    history:createWebHashHistory('/base'),
    routes
})


//导出路由
export default router